home *** CD-ROM | disk | FTP | other *** search
-
-
-
- Swap C Library Procedures Swap
-
-
-
- _________________________________________________________________
-
- NNAAMMEE
- Swap_Buffer - Do byte-swapping and alignment of data buffers
- Swap_BufSize - Calculate the necessary buffer size to hold
- swapped and aligned data
-
- SSYYNNOOPPSSIISS
- ##iinncclluuddee <<sswwaappBBuuffffeerr..hh>>
-
- void SSwwaapp__BBuuffffeerr(_i_n_B_u_f, _i_n_S_i_z_e, _i_n_T_y_p_e, _o_u_t_T_y_p_e, _f_o_r_m_a_t,
- _o_u_t_B_u_f, _o_u_t_S_i_z_e_P_t_r)
-
- void SSwwaapp__BBuuffSSiizzee(_i_n_B_u_f, _i_n_S_i_z_e, _i_n_T_y_p_e, _o_u_t_T_y_p_e, _f_o_r_m_a_t,
- _o_u_t_S_i_z_e_P_t_r)
-
- AARRGGUUMMEENNTTSS
- char *_i_n_B_u_f (in) In-coming data buffer
-
- int _i_n_S_i_z_e (in) Size in bytes of inBuf
-
- int _i_n_T_y_p_e (in) Type of byte-order and
- alignment of data in inBuf
-
- int _o_u_t_T_y_p_e (in) Type of byte-order and
- alignment of data in out-
- Buf
-
- char *_f_o_r_m_a_t (in) String describing format
- of data in inBuf (see
- below for more details)
-
- char *_o_u_t_B_u_f (out) Buffer in which to put
- out-going swapped and
- aligned data
-
- int *_o_u_t_S_i_z_e_P_t_r (in/out) outSizePtr is an in/out
- parameter for
- SSwwaapp__BBuuffffeerr(()), but just an
- out parameter for
- SSwwaapp__BBuuffSSiizzee(()). See below
- for its use in
- SSwwaapp__BBuuffffeerr(()) and
- SSwwaapp__BBuuffSSiizzee(()).
-
- _________________________________________________________________
-
- DDEESSCCRRIIPPTTIIOONN
- These routines are obsolete. See Fmt instead.
-
- SSwwaapp__BBuuffffeerr(()) takes a buffer of data (_i_n_B_u_f) from one
- machine byte-order and alignment type (_i_n_T_y_p_e) and produces
- an output buffer (_o_u_t_B_u_f) of the same data swapped and
- aligned to conform to a different machine byte-order and
-
-
-
- Sprite v.1.0 Printed: June 3, 1991 1
-
-
-
-
-
-
- Swap C Library Procedures Swap
-
-
-
- alignment type (_o_u_t_T_y_p_e). The parameter _o_u_t_S_i_z_e_P_t_r is an
- in/out parameter to SSwwaapp__BBuuffffeerr(()). In a call to
- SSwwaapp__BBuuffffeerr(()), *_o_u_t_S_i_z_e_P_t_r should contain the size in bytes
- of the buffer parameter _o_u_t_B_u_f. As SSwwaapp__BBuuffffeerr(()) returns,
- *_o_u_t_S_i_z_e_P_t_r contains the actual size of the swapped and
- aligned data. If the return value of *_o_u_t_S_i_z_e_P_t_r is larger
- than its input value, then SSwwaapp__BBuuffffeerr(()) needed more buffer
- space for the out-going data than _o_u_t_B_u_f provided. In this
- case, SSwwaapp__BBuuffffeerr(()) stops swapping the data and instead cal-
- culates the amount of space in bytes that it needs. It
- returns that value in *_o_u_t_S_i_z_e_P_t_r. If *_o_u_t_S_i_z_e_P_t_r returns
- with a 0 value, then an error occurred, such as the _f_o_r_m_a_t
- argument contained unrecognizable characters or contained a
- '*' character in a position other than the last character
- (see description of format string, below), or the sizes of
- the _f_o_r_m_a_t string or _i_n_B_u_f weren't compatible. In the case
- of an error, if SSwwaapp__BBuuffffeerr(()) is called from a user process,
- it will panic with an error string explaining the problem.
- If called in the kernel, it will print a warning-level sys-
- tem error message and return.
-
- SSwwaapp__BBuuffSSiizzee(()) calculates the size required for the _o_u_t_B_u_f
- parameter to SSwwaapp__BBuuffffeerr(()) given the same input data
- (_i_n_B_u_f), byte-ordering types (_i_n_T_y_p_e and _o_u_t_T_y_p_e), and the
- same data format (_f_o_r_m_a_t). It returns this calculated value
- in *_o_u_t_S_i_z_e_P_t_r. If *outSizePtr returns with a zero, then an
- error occurred. (See the errors listed above for
- SSwwaapp__BBuuffffeerr(()) for details.) Different machines have dif-
- ferent alignment (and thus padding) requirements, and this
- is why the size of the out-going data may be different from
- the size of the in-coming data.
-
- The format string (_f_o_r_m_a_t) must describe the configuration
- of the data in the input buffer, _i_n_B_u_f. The data can con-
- tain bytes, half-words (4 bytes), words (8 bytes) and
- double-words (16 bytes).
-
- The format string describes these data types as follows:
-
- 'b' The character 'b' stands for a byte value (1 byte).
-
- 'h' The character 'h' stands for a half-word (2 bytes).
-
- 'w' The character 'w' stands for a word (4 bytes).
-
- 'd' The character 'd' stands for a double-word (8 bytes and
- not yet implemented).
-
- '0'-'9'*
- A number in ascii means that the previous value type
- ('b, 'h', 'w', or 'd') is repeated the given number of
- times. For instance, the string "w88" means that inBuf
-
-
-
- Sprite v.1.0 Printed: June 3, 1991 2
-
-
-
-
-
-
- Swap C Library Procedures Swap
-
-
-
- contains 88 word values in a row.
-
- '*' A '*' character means 1 or more occurrences of the pre-
- vious value type. A '*' can only appear at the end of
- a format string, since otherwise there's no way to
- determine the actual number of repetitions of the pre-
- vious value.
-
- An example format string, "bwwh3w5b*", would describe a
- buffer containing the structure
-
- struct flea {
- char mite;
- int spider;
- int worm;
- short moth;
- short mosquito;
- short beetle;
- int fly[5];
- char gnat[50];
- };
-
- The machine byte-order and alignment types are defined in
- swapBuffer.h. Their names may change since complaints have
- been registered about the current names, but currently the
- types are as follows:
-
- SSWWAAPP__SSUUNN__TTYYPPEE
- The byte-ordering and alignment of 68020's. Looking at
- an integer as if it were an array of 4 bytes (char
- buf[4]), buf[0] contains the low byte, buf[3] contains
- the high byte, and half-words and words are aligned to
- half-word boundaries.
-
- SSWWAAPP__VVAAXX__TTYYPPEE
- The byte-ordering and alignment of Vaxen. Looking at
- an integer as if it were an array of 4 bytes (char
- buf[4]), buf[0] contains the high byte, buf[3] contains
- the low byte, and half-words and words are aligned to
- half-word boundaries.
-
- SSWWAAPP__SSPPUURR__TTYYPPEE
- The byte-ordering and alignment of the Spur machine.
- Looking at an integer as if it were an array of 4 bytes
- (char buf[4]), buf[0] contains the high byte, buf[3]
- contains the low byte. Half-words are half-word
- aligned and words are word aligned.
-
- KKEEYYWWOORRDDSS
- byte-order, byte-swap, padding, alignment
-
-
-
-
-
- Sprite v.1.0 Printed: June 3, 1991 3
-
-
-
-